<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>分类管理</title>
  {include file='header'}
  <style>
  .icon{width:50px;height:50px}
  </style>
</head>

<body>
  <div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="">首页</a>
      <a>
        <cite>分类管理</cite></a>
    </span>
    <div style="float: right;">
      <button class="layui-btn" onclick="xadmin.open('添加','{:url('modify')}?parent_id={$parent_id}',650,600)"><i
          class="layui-icon">&#xe61f;</i>添加</button>
      <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>-->
      <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1"></i></a>
    </div>
  </div>
  <div class="x-body">
    <div class="layui-row">
      <form class="layui-form">
        <div class="layui-input-inline layui-show-xs-block">
          <input class="layui-input" placeholder="分类名" name="keyword">
        </div>
        <div class="layui-input-inline layui-show-xs-block">
          <button class="layui-btn" lay-submit="" lay-filter="sreach">搜索</button>
        </div>
      </form>
    </div>
    <div class="layui-row">
      <table class="layui-table">
        <thead>
        <tr>
            <th class='list-table-check-td think-checkbox' style="width:40px">
                <label><input onclick="checkall(this)" type='checkbox'></label>
            </th>
            <th style="width:50px" class='list-table-sort-td'>排序</th>
            <th style="width:60px">图标</th>
            <th class='text-center'>分类名称</th>
            <th>描述</th>
            <th class='layui-hide-xs text-center' style="width:180px">状态</th>
            <th style="width:180px">操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class='list-table-check-td think-checkbox'>
                <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
            </td>
            <td class='list-table-sort-td'>
                <input value="{$vo.sort}" class="list-sort-input">
            </td>
            <td class='text-center'>{if !empty($vo.icon)}<img src="{$vo.icon}" class="icon" />{/if}</td>
            <td class="nowrap"><span class="color-desc">{if !empty($vo.spl)}{$vo.spl|raw}{/if}</span>{$vo.name}</td>
            <td class='layui-hide-xs'>{$vo.icon}</td>
            <td class='text-center nowrap'>
             {if $vo.status eq 1}
                <a class="layui-btn layui-btn-nomal layui-btn-xs" onclick="set_status({$vo.id},0)">禁 用</a>
                {else}
                <a class="layui-btn layui-btn-warm layui-btn-xs" onclick="set_status({$vo.id},1)">启 用</a>
                {/if}
            </td>
            <td class='text-center nowrap notselect'>
                
                <a class="layui-btn layui-btn-xs layui-btn-primary" data-title="添加子菜单" onclick="xadmin.open('添加子菜单','{:url("modify")}?pid={$vo.id}',650,550)">添 加</a>             
                <a data-dbclick class="layui-btn layui-btn-xs" data-title="编辑菜单"  onclick="xadmin.open('编辑菜单','{:url("modify")}?id={$vo.id}&parent_id={$parent_id}',650,750)">编 辑</a>
               
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove({$vo.id})">删 除</a>
            </td>
        </tr>{if !empty($vo['data'])}{foreach $vo['data'] as $v}
        <tr>
          <td class='list-table-check-td think-checkbox'>
              <label><input class="list-check-box" value='{$v.id}' type='checkbox'></label>
          </td>
          <td class='list-table-sort-td'>
              <input data-action-blur="{:request()->url()}" data-value="id#{$v.id};action#sort;sort#{value}" data-loading="false" value="{$v.sort}" class="list-sort-input">
          </td>
          <td class='text-center'>{if !empty($vv.icon)}<img src="{$vv.icon}" class="icon" />{/if}</td>
          <td class="nowrap"><span class="color-desc">{$v.spl|raw}</span>{$v.name}</td>
          <td class='layui-hide-xs'>{$v.memo}</td>
          <td class='text-center nowrap'>
           {if $v.status eq 1}
                <a class="layui-btn layui-btn-nomal layui-btn-xs" onclick="set_status({$v.id},0)">禁 用</a>
                {else}
                <a class="layui-btn layui-btn-warm layui-btn-xs" onclick="set_status({$v.id},1)">启 用</a>
                {/if}
          </td>
          <td class='text-center nowrap notselect'>
                          
              {if $v.level <2}
                <a class="layui-btn layui-btn-xs layui-btn-primary" data-title="添加子菜单" onclick="xadmin.open('添加子菜单','{:url("modify")}?pid={$v.id}',650,550)">添 加</a>
                {else}
                <a class="layui-btn layui-btn-xs layui-btn-disabled">添 加</a>
                {/if}
                <a data-dbclick class="layui-btn layui-btn-xs" data-title="编辑菜单"  onclick="xadmin.open('编辑菜单','{:url("modify")}?id={$v.id}&parent_id={$parent_id}',650,550)">编 辑</a>               
               
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove({$v.id})">删 除</a>
          </td>
      </tr>
      {if !empty($v['data'])}{foreach $v['data'] as $vv}
        <tr>
          <td class='list-table-check-td think-checkbox'>
              <label><input class="list-check-box" value='{$vv.id}' type='checkbox'></label>
          </td>
          <td class='list-table-sort-td'>
              <input data-action-blur="{:request()->url()}" data-value="id#{$vv.id};action#sort;sort#{value}" data-loading="false" value="{$vv.sort}" class="list-sort-input">
          </td>
          <td class='text-center'>{if !empty($vv.icon)}<img src="{$vv.icon}" class="icon" />{/if}</td>
          <td class="nowrap"><span class="color-desc">{$vv.spl|raw}</span>{$vv.name}</td>
          <td class='layui-hide-xs'>{$vv.memo}</td>
          <td class='text-center nowrap'>
              {if $vv.status eq 1}
                <a class="layui-btn layui-btn-nomal layui-btn-xs" onclick="set_status({$vv.id},0)">禁 用</a>
                {else}
                <a class="layui-btn layui-btn-warm layui-btn-xs" onclick="set_status({$vv.id},1)">启 用</a>
                {/if}
              </td>
          <td class='text-center nowrap notselect'>
              {if $vv.level <2}
                <a class="layui-btn layui-btn-xs layui-btn-primary" data-title="添加子菜单" onclick="xadmin.open('添加子菜单','{:url("modify")}?pid={$vv.id}',650,550)">添 加</a>
                {else}
                <a class="layui-btn layui-btn-xs layui-btn-disabled">添 加</a>
                {/if}
                <a data-dbclick class="layui-btn layui-btn-xs" data-title="编辑菜单"  onclick="xadmin.open('编辑菜单','{:url("modify")}?id={$vv.id}&parent_id={$parent_id}',650,550)">编 辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove({$vv.id})">删 除</a>
          </td>
      </tr>{/foreach}
        {/if}
      {/foreach}
      {/if}
      {/foreach}
      </tbody>
      </table>
    </div>
  </div>
  <script type="text/javascript">
  function checkall(obj){       
    if($(obj).is(':checked'))
    {
        $('.list-check-box').prop("checked",true)
    }
    else
    {
        $('.list-check-box').prop("checked",false);
    }        
  }
  function delAll()
  {
    var ids=[];
    $('.list-check-box').each(function(){
      if($(this).is(':checked'))
      {
        ids.push($(this).val());
      }
    })
    if(ids.length==0)
    {
      layer.msg('请选择');
      return;
    }
    $.post("{:url('removeall')}",{ids:ids},function(res){
        if(res.code==1)
        {
          layer.msg('操作成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      },'json');
  }
  function set_status(id,status){
    $.post("{:url('status')}",{id:id,status:status},function(res){
        if(res.code==1)
        {
          layer.msg('操作成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      },'json');
  }
  function remove(id)
  {
    if(confirm('确定要删除数据吗?'))
    {
      $.post("{:url('remove')}",{id:id},function(res){
        if(res.code==1)
        {
          layer.msg('删除成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      })
    }
  }
    function layerOpen()
    {
      layer.open({
        type:2,
        title:'添加',
        content:"{:url('modify')}",
        end:function(){
          location.reload();
        }
      })
    }
    layui.use(['form'], function () {
      form = layui.form;

    });

    /*用户-删除*/
    function member_del(obj, id) {
      layer.confirm('确认要删除吗？', function (index) {
        //发异步删除数据
        $(obj).parents("tr").remove();
        layer.msg('已删除!', { icon: 1, time: 1000 });
      });
    }

    // 分类展开收起的分类的逻辑
    // 
    $(function () {
      
    })    

  </script>
</body>

</html>